$.ajax({
    url: '/classrooms_list.action',

    type:"POST",
    dataType:"JSON",
    success: function(result){
        function classrooms_list(result){
            var slong = '';
            for(var i=0;i<result.data.length;i++){
                // var obj = JSON.parse(result[i]);
                slong = slong + '<tr>\n' +
                    '<td>'+result.data[i].classroom_id+'</td>\n' +
                    '<td>'+result.data[i].building+'</td>\n' +
                    '<td>'+result.data[i].room+'</td>\n' +
                    '<td>'+result.data[i].classroom_capacity+'</td>\n' +
                    '<td>'+result.data[i].multimedia+'</td>\n' +
                    '<td class="td-manage">\n' +
                    '<a title="删除" onclick="classrooms_del(this)" href="javascript:;">\n' +
                    '<i class="layui-icon">&#xe640;</i>\n' +
                    '</a>\n' +
                    '</td>\n' +
                    '</tr>';
            }
            document.getElementById("classroomslisttbody").innerHTML = slong;
        }
        classrooms_list(result);

    },
    error: function() {
        alert("错误提示： " + xhr.status + " " + xhr.statusText);
    },
});


function classrooms_add(){
    var building= document.getElementById('building').value;
    var room =document.getElementById('room').value;

    var classroom_capacity = document.getElementById('classroom_capacity').value;

    var multimedia=document.getElementById('multimedia').value;


    $.ajax({
        url: '/classrooms_add.action',
        data: {
            "building": building,
            "room": room,
            "classroom_capacity":classroom_capacity,
            "multimedia": multimedia
        },
        type: "POST",
        dataType: "JSON",
        success: function () {
            alert("添加成功");
        },

    });}



function classrooms_del(obj) {
    var td = obj.parentNode;
    var index=td.parentNode.rowIndex;
    var classrooms_list = document.getElementById("classrooms_list");
    var id = classrooms_list.rows[index].cells[0].innerHTML;
    classrooms_list.deleteRow(index);
    $.ajax({
        url: '/classrooms_del.action',
        data: {
            "classroom_id": id,
        },
        type: "POST",
        dataType: "JSON",
        success: function () {
            alert("删除成功");
        },
        error: function() {
            alert("删除错误");
        }
    });}
